package com.groupten.ServiceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.groupten.Dao.DictTypeDao;
import com.groupten.Entity.DictTypeEntity;
import com.groupten.Service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("dictTypeService")
public class DictTypeServiceImpl extends ServiceImpl<DictTypeDao, DictTypeEntity> implements DictTypeService {

    @Autowired
    private DictTypeDao dictTypeDao;

    @Override
    public Boolean insert(DictTypeEntity dictTypeEntity) {
        return dictTypeDao.insert(dictTypeEntity) > 0;
    }

    @Override
    public IPage<DictTypeEntity> queryAll(Integer page, Integer limit) {
        int curpage=1;
        int curlimit=10;
        if (page!=null&&page>0){
            curpage=page;
        }
        if (limit!=null&&limit>0){
            curlimit=limit;
        }
        return dictTypeDao.selectPage(new Page<>(curpage,curlimit), Wrappers.lambdaQuery());
    }

    @Override
    public DictTypeEntity queryByTypeName(String typeName) {
        LambdaQueryWrapper<DictTypeEntity> dictTypeEntityLambdaQueryWrapper = new LambdaQueryWrapper<DictTypeEntity>().eq(typeName!=null && !typeName.isEmpty(),DictTypeEntity::getDictTypeName, typeName);
        return dictTypeDao.selectOne(dictTypeEntityLambdaQueryWrapper);
    }

    @Override
    public DictTypeEntity queryById(Integer id) {
        return dictTypeDao.selectById(id);
    }

    @Override
    public Integer deleteById(Integer id) {
        return dictTypeDao.deleteById(id);
    }

    @Override
    public Integer deleteByTypeName(String typename) {
        LambdaQueryWrapper<DictTypeEntity> dictTypeEntityLambdaQueryWrapper = new LambdaQueryWrapper<DictTypeEntity>().eq(typename!=null && !typename.isEmpty(),DictTypeEntity::getDictTypeName, typename);
        return dictTypeDao.delete(dictTypeEntityLambdaQueryWrapper);
    }
}
